#数据库的工具类

import mysql.connector as mysql_conn

#获取连接
def get_conn():
    try:
        conn = mysql_conn.connect(host='localhost',

                                  user='root',
                                  password='2001928',
                                  auth_plugin='mysql_native_password',
                                  database='super',
                                  charset='utf8',
                                  autocommit=True)
        return conn
    except mysql_conn.Error:
        print("数据库连接异常")


#关闭连接
def close_conn(conn,cursor):
    try:
        if cursor:
            cursor.close()
        if conn:
            conn.close()
    except mysql_conn.Error:
        print('数据库关闭异常')
    finally:
        cursor.close()
        conn.close()

